
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>说说Kafka处理请求的全流程？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>说说Kafka处理请求的全流程？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Kafka中的生产者（Producer）和消费者（Consumer）是如何发起请求的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">生产者发送消息时，会选择一个主题（Topic）和分区（Partition），并将请求发送到集群中的一个Broker。消费者请求消息时，也会指定主题和分区，并可能指定一个消费者组（Consumer Group），然后将请求发送给Broker。</div>
          </div>
          <div class="card-source">来源: 1. 客户端请求</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当一个Kafka Broker接收到的请求所指定的分区不在其上时，它会如何处理？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">如果请求的分区信息不在当前Broker上，该Broker会将请求路由到拥有该分区的正确Broker进行处理。</div>
          </div>
          <div class="card-source">来源: 2. Broker 接收请求</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Kafka在写入消息时，是如何保证高吞吐量和数据持久化的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当生产者请求写入消息时，Broker会将消息写入分区的日志文件中。Kafka利用高效的顺序写入机制来保证消息的持久化和高吞吐量。</div>
          </div>
          <div class="card-source">来源: 3. 消息写入</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Kafka是如何通过分区副本机制来保证数据的高可用性和容错性的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">每个分区都有一个领导者（Leader）和若干个副本（Follower）。消息首先被写入领导者分区，然后领导者会异步地将消息复制到所有副本。如果领导者发生故障，系统会从副本中选举一个新的领导者。</div>
          </div>
          <div class="card-source">来源: 3. 消息写入</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Kafka中，消费者是如何跟踪自己已经消费了哪些消息的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">消费者通过维护和提交自己的位移（offset）来跟踪已经消费的消息。位移记录了消费者的消费进度，确保消费者能从正确的位置继续消费。位移可以存储在Kafka内部主题或外部存储系统中。</div>
          </div>
          <div class="card-source">来源: 4. 消息读取</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">如果一个分区的领导者（Leader）Broker发生故障，Kafka会如何处理以保证系统的高可用性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">如果领导者Broker发生故障，Kafka会自动从其副本（Follower）中选举一个新的领导者。新领导者会使用副本中的数据来恢复状态，从而继续处理请求并确保系统的高可用性。</div>
          </div>
          <div class="card-source">来源: 6. 故障处理</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
